/**
 * 
 */
package com.qiyi.myproject.httpclient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

/**
 * @author Dell
 * 
 */
public class HttpClient4RestTest {

	/**
	 * @param args
	 * @throws UnsupportedEncodingException 
	 */
	public static void main(String[] args) throws UnsupportedEncodingException {
		// TODO Auto-generated method stub
		String url1 = "https://bb-gen.test.expressplay.com/hms/bb/token?customerAuthenticator=1107,04aa2d9474e04791b1046b67227dac3e&actionTokenType=1&contentId=urn:marlin:organization:hms-sample:bb:atg&contentKey=12345678123456781234567812345678&rightsType=BuyToOwn";
		String url2 = "https://bb-gen.test.expressplay.com/hms/bb/token";
		String url3 = "https://www.signpost.com/login";
		String url4 = "http://www.baidu.com/";
		
		String customerAuthenticato = "1107,04aa2d9474e04791b1046b67227dac3e";
		String contentId ="cid:marlin#Purn:marlin:iQIYI:hms:bbts@05f5f199";
		String contentKey ="00c345aa62bbe4c720f8812819a3c2a1";
		
		StringBuffer sb = new StringBuffer("https://bb-gen.test.expressplay.com/hms/bb/token?");
		sb.append("customerAuthenticator="+customerAuthenticato);
		sb.append("&actionTokenType="+"1");
		sb.append("&contentId="+URLEncoder.encode(contentId,"UTF-8"));
		sb.append("&contentKey="+URLEncoder.encode(contentKey,"UTF-8"));
//		sb.append("&contentId="+contentId);
//		sb.append("&contentKey="+contentKey);
		sb.append("&rightsType="+"BuyToOwn");
        System.out.println(sb.toString());
		HttpGet httpGet = new HttpGet(sb.toString());
		HttpClient client = new DefaultHttpClient();
		HttpResponse response;
		
		
		try {
			
//			 ResponseHandler<String> responseHandler = new BasicResponseHandler();
			response = client.execute(httpGet);
//			String str = client.execute(httpGet,responseHandler);
			System.out.println(response.getStatusLine().getStatusCode());
			HttpEntity entity = response.getEntity();
			BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));

			StringBuffer content = new StringBuffer();
			for (String line; (line = br.readLine()) != null;) {
				content.append(line + "\r\n");
			}
			System.out.println(content.toString().getBytes().length);

		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
